<template>

  <ContentWrap>
    <el-form
      class="-mb-15px"
      :model="queryParams"
      ref="queryFormRef"
      :inline="true"
      label-width="88px"
    >
      <el-form-item label="缴费日期" prop="searchTime">
        <el-date-picker
          v-model="queryParams.searchTime"
          value-format="YYYY-MM-DD HH:mm:ss"
          type="daterange"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
          class="!w-240px"
        />
      </el-form-item>
      <el-form-item label="缴费状态" prop="status">
        <el-select
          v-model="queryParams.status"
          placeholder="请选择缴费状态"
          clearable
          class="!w-160px"
        >
          <el-option label="全部状态" value=""/>
          <el-option label="缴费成功" value="success"/>
          <el-option label="缴费失败" value="fails"/>
          <el-option label="待支付" value="unpaid"/>
        </el-select>
      </el-form-item>
<!--      <el-form-item label="支付方式" prop="status">-->
<!--        <el-select-->
<!--          v-model="queryParams.payModeName"-->
<!--          placeholder="请选择支付方式"-->
<!--          clearable-->
<!--          class="!w-160px"-->
<!--        >-->
<!--          <el-option label="全部" value=""/>-->
<!--          <el-option label="线上医保微信" value="线上医保微信"/>-->
<!--          <el-option label="微信" value="微信"/>-->
<!--        </el-select>-->
<!--      </el-form-item>-->
      <el-form-item label="门诊号" prop="clinicNo">
        <el-input
          v-model="queryParams.clinicNo"
          placeholder="请输入门诊号"
          clearable
          @keyup.enter="handleQuery"
          class="!w-160px"
        />
      </el-form-item>
      <el-form-item label="挂号单号" prop="registerNo">
        <el-input
          v-model="queryParams.registerNo"
          placeholder="请输入挂号单号"
          clearable
          @keyup.enter="handleQuery"
          class="!w-160px"
        />
      </el-form-item>
      <el-form-item label="平台订单号" prop="orderNo">
        <el-input
          v-model="queryParams.orderNo"
          placeholder="请输入平台订单号"
          clearable
          @keyup.enter="handleQuery"
          class="!w-260px"
        />
      </el-form-item>
      <el-form-item label="病人姓名" prop="patientName">
        <el-input
          v-model="queryParams.patientName"
          placeholder="请输入病人姓名"
          clearable
          @keyup.enter="handleQuery"
          class="!w-160px"
        />
      </el-form-item>
      <el-form-item label="病人ID" prop="patientId">
        <el-input
          v-model="queryParams.patientId"
          placeholder="请输入病人ID"
          clearable
          @keyup.enter="handleQuery"
          class="!w-160px"
        />
      </el-form-item>

      <el-form-item>
        <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
        <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
      </el-form-item>
    </el-form>
  </ContentWrap>

  <!-- 列表 -->
  <ContentWrap>
    <el-table v-loading="loading" border :show-overflow-tooltip="true" :data="list" :row-class-name="tableRowClassName" style="width: 100%;">
      <el-table-column label="病人姓名" align="center" prop="patientName" width="100"/>
      <el-table-column label="病人ID" align="center" prop="patientId" width="100"/>
      <el-table-column label="门诊号" align="center" prop="clinicNo" min-width="100"/>
      <el-table-column label="身份证号" align="center" prop="idCardNo" min-width="150"/>
      <el-table-column label="平台订单号" align="center" prop="orderNumber" min-width="195" />
      <el-table-column label="支付方式" align="center" prop="payWay"  :show-overflow-tooltip="true" />
      <el-table-column label="授权码" align="center" prop="authCode"  :show-overflow-tooltip="true" />
      <el-table-column label="创建时间" align="center" prop="createTime" width="160"  fixed="right"/>
<!--      <el-table-column label="操作" align="center" min-width="125" fixed="right">-->
<!--        <template #default="scope">-->
<!--          <el-button-->
<!--            plain-->
<!--            size="small"-->
<!--            type="primary"-->
<!--            @click="openForm( scope.row.orderNumber)"-->
<!--          >-->
<!--            单据-->
<!--          </el-button>-->

<!--          <el-button-->
<!--            plain-->
<!--            size="small"-->
<!--            type="success"-->
<!--            @click="openPrice( scope.row.orderNumber)"-->
<!--          >-->
<!--            费用-->
<!--          </el-button>-->

<!--        </template>-->
<!--      </el-table-column>-->
    </el-table>
    <!-- 分页 -->
    <Pagination
      :total="total"
      v-model:page="queryParams.pageNo"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />
  </ContentWrap>
  <!-- 表单弹窗：单据 -->
  <order ref="formRef" />
  <!-- 表单弹窗：费用 -->
  <price ref="priceRef" />
</template>
<script lang="ts" setup>
import * as StaticsApi from '@/api/hosp/statics'
import order from './order.vue'
import price from './price.vue'

defineOptions({ name: 'RegisterOrder' })

const message = useMessage() // 消息弹窗

const loading = ref(false) // 列表的加载中
const total = ref(0) // 列表的总页数
const list = ref([]) // 列表的数据
const queryParams = reactive({
  pageNo: 1,
  pageSize: 10,
  searchTime: [],
  patientId: null,
  patientName: null,
  status: null,
  payModeName: null,
  orderNo: null,
  registerNo: null,
  clinicNo: null,
})
const queryFormRef = ref() // 搜索的表单

const tableRowClassName = ({row}) => {
  if (row.procedureStatus === 'success') {
    return 'my-table success-row'
  } else if (row.procedureStatus === 'fails') {
    return 'my-table fails-row'
  } else if (row.procedureStatus === 'REFUND') {
    return 'my-table REFUND-row'
  }
  return 'my-table'
}

/** 搜索按钮操作 */
const handleQuery = () => {
  queryParams.pageNo = 1
  getList()
}

/** 查询列表 */
const getList = async () => {
  loading.value = true
  try {
    const data = await StaticsApi.getQrPage(queryParams)
    list.value = data.list
    total.value = data.total
  } finally {
    loading.value = false
  }
}


const formRef = ref()
const openForm = (orderNumber: string,) => {
  formRef.value.open(orderNumber)
}

const priceRef = ref()
const openPrice = (orderNumber: string,) => {
  priceRef.value.open(orderNumber)
}

/** 重置按钮操作 */
const resetQuery = () => {
  queryFormRef.value.resetFields()
  handleQuery()
}


/** 初始化 **/
onMounted(async () => {
  await getList()
})

</script>
<style scoped>
:deep(.el-table) {
  position: relative;
  overflow: hidden;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  -webkit-box-flex: 1;
  -ms-flex: 1;
  flex: 1;
  width: 100%;
  max-width: 100%;
  font-size: 12px;
  color: #000000;
}
:deep(.REFUND-row) {
  background-color: #F3D39BFF !important;
}

:deep(.fails-row) {
  background-color: #D15B47 !important;
}

:deep(.success-row) {
  background-color: #36bc99 !important;
}
:deep(.my-table td) {
  padding: 5px 0 !important;
}

</style>
